package menus;

import javax.faces.event.ValueChangeEvent;
import user.Role;

/**
 *
 * @author Thorsten Ludwig
 */

public class CategoryContainer {

    private MenuCategory item;

    public CategoryContainer(MenuCategory item) {
        this.item = item;
    }
    
    public boolean getAdminViewRights() {
        return this.item.getRights().hasViewRight(Role.ADMIN);
    }
    
    public boolean getCoAdminViewRights() {
        return this.item.getRights().hasViewRight(Role.COADMIN);
    }
    
    public boolean getTutorViewRights() {
        return this.item.getRights().hasViewRight(Role.TUTOR);
    }
    public boolean getStudentViewRights() {
        return this.item.getRights().hasViewRight(Role.STUDENT);
    }
    
    public boolean getGuestViewRights() {
        return this.item.getRights().hasViewRight(Role.GUEST);
    }
    
    public void adminViewListener(ValueChangeEvent event) {
        boolean wert = (Boolean) event.getNewValue();
        System.out.println("Ändere Wert von " + this.item.getName() + " auf " + wert);
        if (wert)
            this.item.getRights().giveViewRights(Role.ADMIN);
        else
            this.item.getRights().removeViewRights(Role.ADMIN);
    }
    
    public void coadminViewListener(ValueChangeEvent event) {
        boolean wert = (Boolean) event.getNewValue();
        System.out.println("Ändere Wert von " + this.item.getName() + " auf " + wert);
        if (wert)
            this.item.getRights().giveViewRights(Role.COADMIN);
        else
            this.item.getRights().removeViewRights(Role.COADMIN);
    }
    
    public void tutorViewListener(ValueChangeEvent event) {
        boolean wert = (Boolean) event.getNewValue();
        System.out.println("Ändere Wert von " + this.item.getName() + " auf " + wert);
        if (wert)
            this.item.getRights().giveViewRights(Role.TUTOR);
        else
            this.item.getRights().removeViewRights(Role.TUTOR);
    }
    
    public void studentViewListener(ValueChangeEvent event) {
        boolean wert = (Boolean) event.getNewValue();
        System.out.println("Ändere Wert von " + this.item.getName() + " auf " + wert);
        if (wert)
            this.item.getRights().giveViewRights(Role.STUDENT);
        else
            this.item.getRights().removeViewRights(Role.STUDENT);
    }
    
    public void guestViewListener(ValueChangeEvent event) {
        boolean wert = (Boolean) event.getNewValue();
        System.out.println("Ändere Wert von " + this.item.getName() + " auf " + wert);
        if (wert)
            this.item.getRights().giveViewRights(Role.GUEST);
        else
            this.item.getRights().removeViewRights(Role.GUEST);
    }

    public MenuCategory getItem() {
        return item;
    }
    
    
}